<?php
include('../../include/functions.inc.php');
$listCycles = $db->query_select("cllg_college_cycle", "FK_ENTITY=" . $user->entity);
$autoLoad = false;
if (getParam("ID") != NULL || getParam("ID") != "") {
    $autoLoad = true;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Asignacion de Estudiantes</title>
        <link href="../../css/ContentStyle.css" rel="stylesheet" type="text/css" />
        <link href="../../css/tableorderer.css" rel="stylesheet" type="text/css" />
        <link href="../../js/protocalendar/datepicker.css" rel="stylesheet" type="text/css" />
        <link href="../../js/dialog/dialog.2.0.css" rel="stylesheet" type="text/css" />
        <link href="../../bootstrap/css/bootstrap.css" rel="stylesheet" type="text/css" />
        <script src="../../js/jquery.js" type="text/javascript"></script>
        <script src="../../js/prototype.js" type="text/javascript"></script>
        <script src="../../js/jsvalidate.js" type="text/javascript"></script>
        <script src="../../js/protocalendar/prototype-date-extensions.js" type="text/javascript"></script>
        <script src="../../js/protocalendar/datepicker.js"  type="text/javascript"></script>
        <script src="../../js/TableOrderer.js" type="text/javascript"></script>
        <script src="../../js/dialog/dialog.2.0.js" type="text/javascript"></script>
        <script src="../../js/include.js" type="text/javascript"></script>
        <style type="text/css">
            input,
            textarea{
                width: 300px;
            }
            select{
                width: 315px;
            }
        </style>
        <script type="text/javascript">
            var cargos=null;

            showTeach=function(){
                var f=new Hash({tittle:'Listado de Catedraticos',url:'../teachers/list.php',callback:selTeach,width:500,height:500});
                setList(null,f.toObject());
            }
            var currentTeach=null;
            selTeach=function(s){
                $("ID").value=s.ID;
                $("NAME").value=s.NOMBRES+' '+s.APELLIDOS;	
                $("cmdAdd").disabled=false;
                setObservers();
                currentTeach=s;
            }

            showCourses=function(cycle){
                var path="assigns.php?ID="+currentTeach.ID+"&CYCLE="+cycle;
                new TableOrderer("asignaciones",{url:path,callBack:function(s){loadCurso(s.ID);}});
            }

            loadCurso=function(ID){
                $("IDASSIGN").value=ID;
                $("operation").value="edit";
                waitMsg("Cargando...");
                $(document.ASIGNACION).submit();
            }
        </script>
    </head>

    <body>
        <div id="tabs">
            <ul class="nav nav-tabs">
                <li class="active">
                    <a>Asignaciones de catedráticos</a>
                </li>
            </ul>
        </div>
        <div id="tab-cont">
            <div id="rsvErrors"></div>
            <form id="ASIGNACION" name="ASIGNACION" method="GET" action="assign.php">
                <input name="IDASSIGN" type="hidden" id="IDASSIGN" value="" />
                <input name="operation" type="hidden" id="operation" value="new" />
                <table class=""  width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                        <th colspan="2" scope="col">

                        </th>
                    </tr>
                    <tr>
                        <td colspan="2"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                                <tr>
                                    <td width="15%">ID CATEDRATICO </td>
                                    <td width="85%">            <input name="ID" type="text" readonly="readonly" id="ID" 
                                                                       value="<?php echo getParam("ID"); ?>" />
                                        <input name="buscar" onclick="showTeach()" type="button" class="btn btn-small" id="buscar"  value=".." />            </td>
                                </tr>
                                <tr>
                                    <td>NOMBRE </td>
                                    <td><input value="<?php echo getParam("NAME"); ?>"  name="NAME" type="text" id="NAME" readonly="readonly" size="50" /></td>
                                </tr>
                                <tr>
                                    <td>CICLO</td>
                                    <td><select name="CYCLE" id="CYCLE" onchange="showCourses(this.value);">
                                            <option value="">Seleccione</option>
                                            <?php foreach ($listCycles as $it) { ?>
                                                <option value="<?php echo $it["CODE"]; ?>" <?= getParam("CYCLE") == $it["CODE"] ? 'selected="selected"' : '' ?>><?php echo $it["CODE"]; ?> </option>
                                            <?php } ?>
                                        </select></td>
                                </tr>
                            </table>
                        </td>
                    </tr>

                    <tr>
                        <th width="58%" scope="col"><legend style="text-align:left">Cursos Asignados</legend></th>
                        <th style="padding-top:0.8%;"><legend><input name="cmdAdd" disabled="disabled" type="submit" class="btn btn-info" id="cmdAdd" value="Asignar" /></legend></th>
                    </tr>
                    <tr>
                        <td colspan="2" >
                            <DIV id="asignaciones"></DIV>
                            &nbsp;</td>
                    </tr>
                </table>
            </form>
            <?php if ($autoLoad) { ?>
                <script>
                    currentTeach={ID:'<?= getParam("ID") ?>'};
                    $("cmdAdd").disabled=false;
                    showCourses(<?= getParam("CYCLE") ?>);
                </script>
            <?php } ?>
        </div>    
    </body>
</html>
